package cxf.spring.demo.gui.model;

import com.jgoodies.binding.beans.ExtendedPropertyChangeSupport;
import cxf.spring.demo.domain.user.User;

import java.beans.PropertyChangeListener;

/**
 * User: Vlad Vinichenko (akerigan@gmail.com)
 * Date: 27.04.2009
 * Time: 11:29:41
 */
public class UserBean {

    private User user;
    private ExtendedPropertyChangeSupport changeSupport;
    private String password;
    private String passwordConfirm;

    public UserBean() {
        this(new User());
    }

    public UserBean(User user) {
        this.user = user;
        changeSupport = new ExtendedPropertyChangeSupport(this);
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void addPropertyChangeListener(PropertyChangeListener x) {
        changeSupport.addPropertyChangeListener(x);
    }

    public void removePropertyChangeListener(PropertyChangeListener x) {
        changeSupport.removePropertyChangeListener(x);
    }

    public String getLogin() {
        return user.getLogin();
    }

    public void setLogin(String login) {
        String oldLogin = user.getLogin();
        user.setLogin(login);
        changeSupport.firePropertyChange("login", oldLogin, login);
    }

    public String getFirstName() {
        return user.getFirstName();
    }

    public void setFirstName(String firstName) {
        String oldValue = user.getFirstName();
        user.setFirstName(firstName);
        changeSupport.firePropertyChange("firstName", oldValue, firstName);
    }

    public String getLastName() {
        return user.getLastName();
    }

    public void setLastName(String lastName) {
        String oldValue = user.getLastName();
        user.setLastName(lastName);
        changeSupport.firePropertyChange("lastName", oldValue, lastName);
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        String oldValue = this.password;
        this.password = password;
        changeSupport.firePropertyChange("password", oldValue, password);
    }

    public String getPasswordConfirm() {
        return passwordConfirm;
    }

    public void setPasswordConfirm(String passwordConfirm) {
        this.passwordConfirm = passwordConfirm;
    }

}
